﻿using LandPortMoblieWeb.Filter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LandPortMoblieWeb.Service;
using LandPortMoblieWeb.Models;
using System.Configuration;

namespace LandPortMoblieWeb.Controllers
{
 
    public class HomeController : Controller
    {
        //主页
        public ActionResult Index()
        {
            var uid = Helper.HelpCookies.CurrentUserObject.Id;

            var par=new PermissionService().GetUserPermiss(uid,"报表");
            ViewBag.menu = par;

            var wenzhang = new PermissionService().GetUserPermiss(uid, "知识管理");

            ViewBag.Knowledge = wenzhang;

            var article = new KnowledgeService().AllKtypeitems(null);

            ViewBag.ArticleType = article;

            return View();
        }

        public ActionResult javascript()
        {
            return Content("alert('Hello World!');", "application/x-javascript");
        }

        /// <summary>
        /// 显示文章内容
        /// </summary>
        /// <returns></returns>
        public ActionResult About()
        {

            var theme = Request["themeid"].ToString();

            var data = new KnowledgeService().GetSingAcr(theme);

            ViewBag.data = data;

            return View();
        }

        /// <summary>
        /// 显示类别下的文章列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Contact()
        {
            var typeid = Request["typeid"].ToString();

            var Article = new KnowledgeService().AllKtypeitems(typeid);

            ViewBag.Know = Article;

            return View();
        }

        [ValidateInput(false)]
        public ActionResult DownLoad(string id, int num)
        {
          //  var path = this.Server.MapPath("~");

            var pp = System.Configuration.ConfigurationManager.AppSettings["DwonLoadPath"].ToString();
           // path += @"uploads";
            var filename = "";
            var items = new Service.KnowledgeService().GetSingAcr(id);
            if (num == 1)
            {
                pp += @"\" + items.FileOne;
                var cc = (items.FileOne).Split('_');
                filename = cc[1];
            }
            else
            {
                pp += @"\" + items.FileTwo;
                var cc = (items.FileTwo).Split('_');
                filename = cc[1];
            }

            return File(pp, "application/vnd.ms-excel", filename);
        }


        public ActionResult MassageInfo()
        {
            var data = new MassageService().GetList(true);
            ViewBag.massage = data;
            return View();
        }

        public ActionResult MassageDetails()
        {
            var id = Request["id"].ToString();

            var dat = new MassageService().GetSinlge(id);
            ViewBag.data = dat;

            return View(dat);
        }

        [ValidateInput(false)]
        public ActionResult MassageDownLoad(string id, int num)
        {
            //  var path = this.Server.MapPath("~");

            var pp = System.Configuration.ConfigurationManager.AppSettings["MassageDwonLoadPath"].ToString();
            // path += @"uploads";
            var filename = "";
            var items = new MassageService().GetSinlge(id);
            if (num == 1)
            {
                pp += @"\" + items.File1;
                var cc = (items.File1).Split('_');
                filename = cc[1];
            }
            else
            {
                pp += @"\" + items.File2;
                var cc = (items.File2).Split('_');
                filename = cc[1];
            }

            return File(pp, "application/vnd.ms-excel", filename);
        }
    }
}
